package cn.tianjindong.blog_portal.interceptor;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 该类用于登记最后一次访问的页面
 * @author 田 金 东
 *
 */
public class LogInterceptor implements HandlerInterceptor {

	private static final String REQUEST_URL="requestUrl";
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String url = request.getServletPath();
		Cookie cookie = new Cookie(REQUEST_URL, url);
		cookie.setPath("/"+request.getContextPath());
		response.addCookie(cookie);
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}
	
}
